package com.wc.AlgoOJ._博弈论.取球游戏;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author congge
 * @Date 2024/4/16 16:31
 * @description http://43.138.190.70:8888/p/LQ0302
 */
public class Main {
    static int N = 10010;
    static int[] f = new int[N];
    static Scanner sc = new Scanner(System.in);
    static int T, n;

    public static void main(String[] args) {
        Arrays.fill(f, -1);
        sg(10000);
        T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            if (f[n] > 0) System.out.println("1");
            else System.out.println("0");
        }
    }

    static int sg(int u) {
        if (f[u] != -1) return f[u];
        Set<Integer> set = new HashSet<>();
        if (u > 8) set.add(sg(u - 8));
        if (u > 7) set.add(sg(u - 7));
        if (u > 3) set.add(sg(u - 3));
        if (u > 1) set.add(sg(u - 1));
        for (int i = 0; ; i++) {
            if (!set.contains(i)) {
                f[u] = i;
                break;
            }
        }
        return f[u];
    }
}
